<?php
 
class SPDO extends PDO{

	private $dsn;
  	private static $instancia = null;

	public function __construct() {
    	try {
      		$config = Config::singleton();
      		$this->dsn = 'mysql:host='.$config->get('db_host').';dbname='.$config->get('db_name');
      		parent::__construct($this->dsn, $config->get('db_user'), $config->get('db_pass'));
      		parent::setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
      		parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    	}
    	catch (PDOException $e) {
      		throw $e;
    	}
	}

  	public static function singleton() {
    	try {
      		if(self::$instancia == null){
        		self::$instancia = new self();
      		}
      		return self::$instancia;
    	}
    	catch(Exception $e){
      		throw $e;
    	}
  	}

}
?>
